﻿namespace TheSafety.Management
{
    using Agent;
    using System;
    using System.CodeDom.Compiler;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using System.Threading;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Markup;
    using System.Windows.Media.Imaging;

    [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
    public class ProlongItem : UserControl, IComponentConnector
    {
        private EventHandler<RoutedEventArgs> a;
        private SynchronizationContext b;
        private ManagementInfoItem c = new ManagementInfoItem();
        private string d = "";
        internal Label e;
        internal Label f;
        internal Label g;
        internal Label h;
        internal Label i;
        internal Label j;
        internal Label k;
        internal Label l;
        internal Label m;
        internal Label n;
        internal Button o;
        internal Button p;
        internal Label q;
        internal Label r;
        internal TextBox s;
        internal ComboBox t;
        internal Image u;
        private bool v;
        [CompilerGenerated]
        private string w;
        [CompilerGenerated]
        private string x;

        public ProlongItem()
        {
            this.InitializeComponent();
            this.b();
        }

        private void a()
        {
            Func<ManagementPromoCode, bool> predicate = null;
            Func<ManagementPromoCode, bool> func2 = null;
            if (this.t.SelectedItem != null)
            {
                float num = float.Parse(((this.t.SelectedItem as ComboBoxItem).Tag as ManagementPeriodItem).a());
                float num2 = float.Parse(((this.t.SelectedItem as ComboBoxItem).Tag as ManagementPeriodItem).b());
                float num3 = 0f;
                if (predicate == null)
                {
                    predicate = new Func<ManagementPromoCode, bool>(this.b);
                }
                if (this.c.c().Count<ManagementPromoCode>(predicate) > 0)
                {
                    string str = "";
                    if (func2 == null)
                    {
                        func2 = new Func<ManagementPromoCode, bool>(this.a);
                    }
                    str = this.c.c().First<ManagementPromoCode>(func2).a();
                    if (!string.IsNullOrWhiteSpace(str))
                    {
                        num3 = float.Parse(str);
                    }
                }
                float num4 = (num * (1f - (num3 / 100f))) * (1f - (num2 / 100f));
                this.l.Content = num.ToString() + " USD";
                this.n.Content = num4.ToString() + " USD";
            }
        }

        public void a(EventHandler<RoutedEventArgs> A_0)
        {
            EventHandler<RoutedEventArgs> handler2;
            EventHandler<RoutedEventArgs> a = this.a;
            do
            {
                handler2 = a;
                EventHandler<RoutedEventArgs> handler3 = (EventHandler<RoutedEventArgs>) Delegate.Remove(handler2, A_0);
                a = Interlocked.CompareExchange<EventHandler<RoutedEventArgs>>(ref this.a, handler3, handler2);
            }
            while (a != handler2);
        }

        [CompilerGenerated]
        private bool a(ManagementPromoCode A_0)
        {
            return (A_0.b() == this.d);
        }

        private string a(DateTime A_0)
        {
            TimeSpan span = A_0.Subtract(DateTime.Now);
            return string.Concat(new object[] { span.Days, e.c("d"), " ", span.Hours, e.c("h"), " ", span.Minutes, e.c("m") });
        }

        [CompilerGenerated]
        private void a(object A_0)
        {
            foreach (ManagementPeriodItem item in this.c.b())
            {
                ComboBoxItem newItem = new ComboBoxItem {
                    Content = item.d(),
                    Tag = item
                };
                this.t.Items.Add(newItem);
            }
            this.t.SelectedIndex = 0;
        }

        private DateTime a(string A_0)
        {
            double result = 0.0;
            double.TryParse(A_0, out result);
            DateTime time = new DateTime(0x7b2, 1, 1, 0, 0, 0);
            return time.AddSeconds(result);
        }

        [DebuggerNonUserCode, EditorBrowsable(EditorBrowsableState.Never)]
        private void a(int A_0, object A_1)
        {
            switch (A_0)
            {
                case 1:
                    ((ProlongItem) A_1).Loaded += new RoutedEventHandler(this.UserControl_Loaded);
                    return;

                case 2:
                    this.e = (Label) A_1;
                    return;

                case 3:
                    this.f = (Label) A_1;
                    return;

                case 4:
                    this.g = (Label) A_1;
                    return;

                case 5:
                    this.h = (Label) A_1;
                    return;

                case 6:
                    this.i = (Label) A_1;
                    return;

                case 7:
                    this.j = (Label) A_1;
                    return;

                case 8:
                    this.k = (Label) A_1;
                    return;

                case 9:
                    this.l = (Label) A_1;
                    return;

                case 10:
                    this.m = (Label) A_1;
                    return;

                case 11:
                    this.n = (Label) A_1;
                    return;

                case 12:
                    this.o = (Button) A_1;
                    this.o.Click += new RoutedEventHandler(this.btnBack_Click);
                    return;

                case 13:
                    this.p = (Button) A_1;
                    this.p.Click += new RoutedEventHandler(this.btnSubmit_Click);
                    return;

                case 14:
                    this.q = (Label) A_1;
                    return;

                case 15:
                    this.r = (Label) A_1;
                    return;

                case 0x10:
                    this.s = (TextBox) A_1;
                    this.s.KeyUp += new KeyEventHandler(this.txtPromo_KeyUp);
                    return;

                case 0x11:
                    this.t = (ComboBox) A_1;
                    this.t.SelectionChanged += new SelectionChangedEventHandler(this.ddlPeriod_SelectionChanged);
                    return;

                case 0x12:
                    this.u = (Image) A_1;
                    return;
            }
            this.v = true;
        }

        private void b()
        {
            this.o.Content = e.c("Back");
            this.p.Content = e.c("ProlongSubscription");
            this.h.Content = e.c("Expires") + ":";
            this.e.Content = e.c("Subscribtion") + ":";
            this.g.Content = e.c("VPNUsername") + ":";
            this.k.Content = e.c("Cost") + ":";
            this.m.Content = e.c("Total") + ":";
            this.q.Content = e.c("Period") + ":";
            this.r.Content = e.c("PromoCode") + ":";
        }

        [CompilerGenerated]
        private bool b(ManagementPromoCode A_0)
        {
            return (A_0.b() == this.d);
        }

        public void b(EventHandler<RoutedEventArgs> A_0)
        {
            EventHandler<RoutedEventArgs> handler2;
            EventHandler<RoutedEventArgs> a = this.a;
            do
            {
                handler2 = a;
                EventHandler<RoutedEventArgs> handler3 = (EventHandler<RoutedEventArgs>) Delegate.Combine(handler2, A_0);
                a = Interlocked.CompareExchange<EventHandler<RoutedEventArgs>>(ref this.a, handler3, handler2);
            }
            while (a != handler2);
        }

        [CompilerGenerated]
        private void b(object A_0)
        {
            SendOrPostCallback d = null;
            <>c__DisplayClass5 class2;
            string a = "";
            this.b.Send(new SendOrPostCallback(class2.c), null);
            if (!string.IsNullOrWhiteSpace(a))
            {
                MessageBox.Show(a);
            }
            else
            {
                if (d == null)
                {
                    d = new SendOrPostCallback(this.a);
                }
                this.b.Send(d, null);
            }
        }

        private void btnBack_Click(object A_0, RoutedEventArgs A_1)
        {
            if (this.a != null)
            {
                this.a(A_0, A_1);
            }
        }

        private void btnSubmit_Click(object A_0, RoutedEventArgs A_1)
        {
            <>c__DisplayClassa classa;
            object b = A_0;
            RoutedEventArgs c = A_1;
            new Thread(new ParameterizedThreadStart(classa.d)) { IsBackground = true }.Start(null);
        }

        private void ddlPeriod_SelectionChanged(object A_0, SelectionChangedEventArgs A_1)
        {
            this.a();
        }

        [DebuggerNonUserCode]
        public void InitializeComponent()
        {
            if (!this.v)
            {
                this.v = true;
                Uri resourceLocator = new Uri("/TheSafety;component/management/prolongitem.xaml", UriKind.Relative);
                Application.LoadComponent(this, resourceLocator);
            }
        }

        private void txtPromo_KeyUp(object A_0, KeyEventArgs A_1)
        {
            Func<ManagementPromoCode, bool> predicate = null;
            this.d = "";
            string a = (A_0 as TextBox).Text;
            if (!string.IsNullOrWhiteSpace(a) && (this.c != null))
            {
                this.u.Visibility = Visibility.Visible;
                if (predicate == null)
                {
                    <>c__DisplayClass11 class2;
                    predicate = new Func<ManagementPromoCode, bool>(class2.b);
                }
                if (this.c.c().Count<ManagementPromoCode>(predicate) > 0)
                {
                    this.d = a;
                    this.u.Source = new BitmapImage(new Uri("pack://application:,,,/thesafety;component/Resources/accept.png"));
                }
                else
                {
                    this.u.Source = new BitmapImage(new Uri("pack://application:,,,/thesafety;component/Resources/delete.png"));
                }
            }
            else
            {
                this.u.Visibility = Visibility.Hidden;
            }
            this.a();
        }

        private void UserControl_Loaded(object A_0, RoutedEventArgs A_1)
        {
            this.b = SynchronizationContext.Current;
            this.j.Content = this.a(this.d()).ToShortDateString() + " (" + this.a(this.a(this.d())) + ")";
            new Thread(new ParameterizedThreadStart(this.b)) { IsBackground = true }.Start(null);
        }

        public string PropDate
        {
            [CompilerGenerated]
            get
            {
                return this.w;
            }
            [CompilerGenerated]
            set
            {
                this.w = value;
            }
        }

        public string PropOrderID
        {
            [CompilerGenerated]
            get
            {
                return this.x;
            }
            [CompilerGenerated]
            set
            {
                this.x = value;
            }
        }

        public string PropSubscription
        {
            set
            {
                this.f.Content = value;
            }
        }

        public string PropVpnUserName
        {
            set
            {
                if (value == "GUI License")
                {
                    this.g.Visibility = Visibility.Hidden;
                    this.i.Visibility = Visibility.Hidden;
                    this.e.Content = e.c("GUILicense") + ":";
                }
                else
                {
                    this.i.Content = value;
                }
            }
        }
    }
}

